
package com.cari.baju.yog;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.cari.baju.yog.database.Database;
import com.cari.baju.yog.entity.E_Toko;

public class TokoActivity extends ActionBarActivity implements OnClickListener {

    private TextView title, alamat, phone;
    private Button btnDirection, btnCall, btnShare;
    private Bundle data;
    private E_Toko toko;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toko);

        getSupportActionBar().setTitle("Cari Baju Yog");

        data = getIntent().getExtras();

        if (data != null) {
            toko = Database.getInstance(this).getToko(data.getInt("id"));
        }

        title = (TextView) findViewById(R.id.title);
        alamat = (TextView) findViewById(R.id.alamat);
        phone = (TextView) findViewById(R.id.phone);
        btnCall = (Button) findViewById(R.id.btn_call);
        btnDirection = (Button) findViewById(R.id.btn_direction);
        btnShare = (Button) findViewById(R.id.btn_share);

        title.setText(toko.getName());
        alamat.setText(toko.getAddress());
        phone.setText(toko.getPhone());

        btnCall.setOnClickListener(this);
        btnDirection.setOnClickListener(this);
        btnShare.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v == btnDirection) {

            Intent i = new Intent(
                    android.content.Intent.ACTION_VIEW,
                    Uri.parse("http://maps.google.com/maps?daddr="
                            + toko.getLat() + "," + toko.getLng()));
            startActivity(i);

        } else if (v == btnCall) {

            Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + toko.getPhone()));
            startActivity(intent);
        } else if (v == btnShare) {
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT,
                    "" + toko.getName() + " " + toko.getAddress()
                            + " telp : " + toko.getPhone() + " lat :" + toko.getLat() + " lng :"
                            + toko.getLng());
            sendIntent.setType("text/plain");

            startActivity(Intent.createChooser(sendIntent, "asfasf"));
        }
    }
}
